package com.qubuyer.business.mine.activity

import android.os.Bundle
import android.view.View
import com.qubuyer.R
import com.qubuyer.business.mine.viewmodel.WalletViewModel
import com.qubuyer.core.app.MVVMFragment
import com.qubuyer.databinding.FragmentMineWalletBinding
import com.qubuyer.utils.StringUtil

/**
 * @author Susong
 * @date 创建时间:2019/4/1
 * @description 我的钱包activity
 * & @version
 */
class MineWalletFragment : MVVMFragment<FragmentMineWalletBinding, WalletViewModel>() {

    override fun getTitle(): String {
        return "我的钱包"
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        viewModel.wallet.observe(viewLifecycleOwner, {
            viewDataBinding.tvTotalMoney.text = StringUtil.formatAmount(it.money, 2)
            viewDataBinding.tvDisOrderProjectedIncome.text =
                "预计收入：" + StringUtil.formatAmount(it.restore, 2) + "元"
            viewDataBinding.tvSaleTotalProjectedIncome.text =
                "预计收入：" + StringUtil.formatAmount(it.distribut, 2) + "元"
        })
    }

    fun onClick(v: View) {
        when (v.id) {
            R.id.rl_line_credit -> {
            }
            R.id.tv_withdraw -> mContext.swapContentFragment(WithdrawFragment())
            R.id.rl_dis_order -> mContext.swapContentFragment(RebateOrderFragment())
            R.id.rl_sale_total -> mContext.swapContentFragment(SaleAmountFragment())
            R.id.rl_income_expenditure -> mContext.swapContentFragment(IncomeFragment())
        }
    }

    override fun onDataBinding(dataBinding: FragmentMineWalletBinding) {
        dataBinding.host = this
    }

    override val viewModel: WalletViewModel by injectVMByActivity()
    override val layoutId: Int
        get() = R.layout.fragment_mine_wallet
}